/**
 * @description 单选组件
 * @author 大肘子
 */

import React, { FC } from 'react'
import style from './index.module.scss'

type QuestionRadioType = {
  fe_id: string
  props: {
    title: string
    isvertical: boolean
    options: Array<{ text: string; value: string }>
    defaultselected: string
  }
}

const QuestionRadio: FC<QuestionRadioType> = ({ fe_id, props }) => {
  const { title, isvertical = false, options = [], defaultselected = '' } = props
  const classname = isvertical ? 'isvertival' : 'ishorizon'
  return (
    <>
      <p className={style.title}>{title}</p>
      <div className={`${style.question} ${style[classname]}`}>
        {options.map(({ text, value:val }) => {
          return (
            <div key={val} className={style.radioitem}>
              <label >
                <input type="radio" name={fe_id} value={val}  defaultChecked={defaultselected == val}></input>
                <span className={style.radiospan}>{text}</span>
              </label>
            </div>
          )
        })}
      </div>
    </>
  )
}

export default QuestionRadio
